package com.boyon.system.action;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.boyon.common.domain.UserSession;
import com.boyon.common.status.Constant;
import com.boyon.system.entity.Account;
import com.boyon.system.entity.Menu;
import com.boyon.system.entity.Role;
import com.boyon.system.service.RoleService;
import com.boyon.web.param.annotation.ValidatorRequestBody;
import com.boyon.web.response.SuccessResponse;

/**
 * ClassName:LoginAction <br/>
 * Function: 登录用户相关请求. <br/>
 * Date: 2018年3月15日 下午5:47:45 <br/>
 * 
 * @author sunshulin
 * @version
 * @since JDK 1.8
 * @see
 */
@Controller
@RequestMapping(value = "/boyon/index", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class LoginAction {

	@Autowired
	private RoleService roleService;

	/**
	 * 
	 * findMenuByRoleId:查找角色菜单. <br/>
	 * 
	 * @author sunshulin
	 * @param account
	 * @return
	 * @since JDK 1.8
	 */
	@RequestMapping(value = "/menu")
	@ResponseBody
	public Menu findMenuByRoleId(@ValidatorRequestBody Account account, HttpSession session) {
		UserSession entity = (UserSession) session.getAttribute(Constant.SESSION_USER);
		Role role = roleService.findByRoleId(entity.getRoleId());
		return roleService.filterMenuByRoleId(role.getRoleId());
	}

	/**
	 * 
	 * findButtonByRoleId:查找角色操作按钮. <br/>
	 * 
	 * @author sunshulin
	 * @param account
	 * @return
	 * @since JDK 1.8
	 */
	@RequestMapping(value = "/button")
	@ResponseBody
	public SuccessResponse findButtonByRoleId(
			@ValidatorRequestBody Account account) {
		return new SuccessResponse(
				roleService.filterButtonByRoleId(account.getRoleId()));
	}
}
